package com.zlz.m3u8download.controller;

import com.zlz.m3u8download.bean.RunTimeTask;
import com.zlz.m3u8download.service.TaskService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/task")
@CrossOrigin(origins = {"http://localhost:8080/"}, allowCredentials = "true")
public class TaskController {

    @Resource
    private TaskService taskService;

    @GetMapping("/stop/{taskId}")
    public void createCacheTask(@PathVariable Long taskId)  {
        taskService.stopTask(taskId);
    }

    @GetMapping("/state")
    public Collection<RunTimeTask> taskState() {
        Map<Long, RunTimeTask> runningTask = new HashMap<>();
        return runningTask.values();
    }
}
